package com.yisu.auction.manager.core.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.yisu.auction.ewf.common.utils.ValidateUtils;
import com.yisu.auction.manager.core.service.IEditorActionService;
import com.yisu.auction.manager.domain.response.UploadImageResult;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * author: 赵杰
 * Business Description： 图片上传业务接口实现
 * createTime：2017/8/9
 */
@Service
public class EditorActionServiceImpl extends BaseService implements IEditorActionService {

    /**
     * 通用图片上传
     *
     * @param file 图片流
     * @return
     */
    @Override
    public UploadImageResult UploadImage(MultipartFile file) {
        UploadImageResult uploadImageResult = new UploadImageResult();
        String imagePath = "";
        if (file != null && ValidateUtils.isImageType(file.getContentType())) {
            imagePath = uploadFile(file);
        }
        if (!StringUtils.isEmpty(imagePath)) {
            uploadImageResult.setState("SUCCESS ");
            uploadImageResult.setUrl(imagePath);
            uploadImageResult.setOriginal(imagePath);
            uploadImageResult.setTitle(imagePath);
        }
        return uploadImageResult;
    }

}
